<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateSystemUser extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('system_user',['engine'=>'InnoDB'])->setComment('系统-用户表');
        $table->addColumn(Column::string('username',50)->setNullable()->setComment('用户账号'));
        $table->addColumn(Column::string('password',32)->setNullable()->setComment('用户密码'));
        $table->addColumn(Column::string('qq',16)->setNullable()->setComment('联系QQ'));
        $table->addColumn(Column::string('mail',32)->setNullable()->setComment('联系邮箱'));
        $table->addColumn(Column::string('phone',16)->setNullable()->setComment('联系手机'));
        $table->addColumn(Column::dateTime('login_at')->setNullable()->setComment('登录时间'));
        $table->addColumn(Column::string('login_ip',15)->setNullable()->setComment('登录IP'));
        $table->addColumn(Column::bigInteger('login_num')->setDefault(0)->setComment('登录次数'));
        $table->addColumn(Column::string('authorize')->setNullable(0)->setComment('权限授权'));
        $table->addColumn(Column::string('desc')->setNullable(0)->setComment('备注说明'));
        $table->addColumn(Column::tinyInteger('status')->setDefault(1)->setComment('状态(0:禁用,1:启用)'));
        $table->addColumn(Column::tinyInteger('is_deleted')->setDefault(0)->setComment('删除(1:删除,0:未删)'));
        $table->addTimestamps('create_at');
        $table->create();
    }
}
